package com.heima.thread.safe.sellTickets2;

import com.heima.thread.safe.sellTickets1.MyThread;

public class MyRunnable implements Runnable{

    // 只有一个Runnable对象, 不用static
    int ticket = 0;

    @Override
    public void run() {
        while(true)
        {
            if (method()) break;
        }
    }

    private synchronized boolean method() {
        if(ticket >= 1000){
            return true;
        }
        Thread t = Thread.currentThread();
        ++ticket;
        System.out.println(t.getName()+"正在卖第"+ticket+"张票");
        return false;
    }
}
